package actor.controller
{
	import actor.Tower;
	import actor.attribute.TowerAttribute;
	import actor.event.TowerEvent;

	public class TowerUpgradeController
	{
		private var _tower:Tower;
		
		private var _attribute:TowerAttribute;
		
		private var _arrDamage:Array;
		private var _arrRange:Array;
		private var _arrAttackSpeed:Array;
		private var _arrUpgradeTime:Array;
		private var _arrDelayTime:Array;
		private var _arrBulletCount:Array;
		
		private var _arrCriticalStrikeRate:Array;
		private var _arrCriticalStrikeMulti:Array;
		private var _arrStunRate:Array;
		private var _arrStunDamage:Array;
		private var _arrStunDuration:Array;
		
		public function TowerUpgradeController( tower:Tower )
		{
			_tower = tower;
			init();
		}
		
		private function init():void
		{
			_attribute = _tower.attribute as TowerAttribute;
		}
		
		public function setDamageArr( arr:Array ):void
		{
			_arrDamage = arr;
		}
		
		public function setRangeArr( arr:Array ):void
		{
			_arrRange = arr;
		}
		
		public function setAttackSpeedArr( arr:Array ):void
		{
			_arrAttackSpeed = arr;
		}
		
		public function setUpgradeTimeArr( arr:Array ):void
		{
			_arrUpgradeTime = arr;
		}
		
		public function setDelayTimeArr( arr:Array ):void
		{
			_arrDelayTime = arr;
		}
		
		public function setBulletCountArr( arr:Array ):void
		{
			_arrBulletCount = arr;
		}
		
		public function setCriticalStrikeRate( arr:Array ):void
		{
			_arrCriticalStrikeRate = arr;
		}
		
		public function setCriticalStrikeMulti( arr:Array ):void
		{
			_arrCriticalStrikeMulti = arr;
		}
		
		public function setStunRate( arr:Array ):void
		{
			_arrStunRate = arr;
		}
		
		public function setStunDamage( arr:Array ):void
		{
			_arrStunDamage = arr;
		}
		
		public function setStunDuration( arr:Array ):void
		{
			_arrStunDuration = arr;
		}
		
		public function upgradeComplete():void
		{
			_attribute.setDamage( int(_arrDamage[_attribute.level-1]), false );
			_attribute.setRange( int(_arrRange[_attribute.level-1]), false );
			_attribute.setAttackSpeed( int(_arrAttackSpeed[_attribute.level-1]), false );
			_attribute.setDelayTime( int(_arrDelayTime[_attribute.level-1]), true );
			_attribute.setBulletCount( int(_arrBulletCount[_attribute.level-1]), true );
			_attribute.setCriticalStrikeRate( int(_arrCriticalStrikeRate[_attribute.level-1]), true );
			_attribute.setCriticalStrikeMulti( Number(_arrCriticalStrikeMulti[_attribute.level-1]), true );
			_attribute.setStunRate( int(_arrStunRate[_attribute.level-1]), true );
			_attribute.setStunDamage( int(_arrStunDamage[_attribute.level-1]), true );
			_attribute.setStunDuration( int(_arrStunDuration[_attribute.level-1]), true );
			
			_tower.dispatchEvent( new TowerEvent( TowerEvent.UPGRADE_COMPLETE ) );
		}
	}
}